package com.sky.web.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    // 订单搜索
    @GetMapping("/conditionSearch")
    public Result search(OrdersPageQueryDTO dto) {
        return Result.success(orderService.findByPage(dto));
    }

    // 统计各个状态的订单数量
    @GetMapping("/statistics")
    public Result statistics() {
        OrderStatisticsVO vo = orderService.statistics();
        return Result.success(vo);
    }

    // 查询订单详情
    @GetMapping("/details/{id}")
    public Result details(@PathVariable("id") Long id) {
        return Result.success(orderService.findByOrderId(id));
    }

    // 接单
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO dto) {
        orderService.confirm(dto);
        return Result.success();
    }
    // 拒单
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO dto) {
        orderService.rejection(dto);
        return Result.success();
    }


    // 取消订单
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO dto){
        orderService.cancelByAdmin(dto);
        return Result.success();
    }

    // 派送订单
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable("id") Long id) {
        orderService.delivery(id);
        return Result.success();
    }

    // 完成订单
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable("id") Long id) {
        orderService.complete(id);
        return Result.success();
    }
}
